|
The Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file systems because of classloaders. Delegation is an important concept to understand when learning about classloaders. A software library is a collection of related object code. In the Java language, libraries are typically packaged in JAR files. Libraries can contain objects of different types. The most important type of object contained in a Jar file is a Java class. A class can be thought of as a named unit of code. The class loader is responsible for locating libraries, reading their contents, and loading the classes contained within the libraries. This loading is typically done "on demand", in that it does not occur until the class is called by the program. A class with a given name can only be loaded once by a given classloader. Each Java class must be loaded by a class loader. Furthermore, Java programs may make use of external libraries (that is, libraries written and provided by someone other than the author of the program) or they may be composed, at least in part, of a number of libraries. When the JVM is started, three class loaders are used: # Bootstrap class loader # Extensions class loader # System class loader The bootstrap class loader loads the core Java libraries〔These libraries are stored in Jar files called ''rt.jar'', ''core.jar'', ''server.jar'', etc.〕 located in the directory. This class loader, which is part of the core JVM, is written in native code.The extensions class loader loads the code in the extensions directories ( ,〔http://docs.oracle.com/javase/tutorial/ext/basics/load.html〕 or any other directory specifiedby the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.The system class loader loads code found on java.class.path , which maps to the CLASSPATH environment variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.==User-defined class loaders== The Java class loader is written in Java. It is therefore possible to create your own class loader without understanding the finer details of the Java Virtual Machine. Every Java class loader has a parent class loader, defined when a new class loader is instantiated or set to the virtual machine's system default class loader. This makes it possible (for example): * to load or unload classes at runtime (for example to load libraries dynamically at runtime, even from an HTTP resource). This is an important feature for: * * implementing scripting languages, such as Jython * * using bean builders * * allowing user-defined extensibility * * allowing multiple namespaces to communicate. This is one of the foundations of CORBA / RMI protocols for example. * to change the way the bytecode is loaded (for example, it is possible to use encrypted Java class bytecode). * to modify the loaded bytecode (for example, for load-time weaving of aspects when using aspect-oriented programming). 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Java Classloader」の詳細全文を読む スポンサード リンク
|